<template>
  <div class="page">
    <div class="weui-search-bar" id="searchBar">
      <form class="weui-search-bar__form">
        <div class="weui-search-bar__box">
          <i class="weui-icon-search" ></i>
          <input type="search" class="weui-search-bar__input" v-model="searchName" id="searchInput" @change="getValue" placeholder="搜索" required="">
          <a href="javascript:" class="weui-icon-clear" id="searchClear" @click="searchName=''"></a>
        </div>
      </form>
      <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
    </div>
    <div class="history">
      <div class="weui-flex">
        <div class="weui-flex__item">历史记录</div>
        <div class="clear" @click="clearFun"><img src="../../../static/images/ic_del.png" mode="widthFix"></div>
      </div>
      <div class="history_list" v-if="getList.length">
        <div class="weui-flex history_item" v-for="item in getList">
          <div class="weui-flex__item">历史记录</div>
          <div @click="getProduct(item)">{{item.name}}</div>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  import * as appId from "@/utils/util"
export default {
  data () {
    return {
      value:"",
      phone:"",
      userId:"",
      changeId:"",
      searchName:"",
      list:[],
      getList:[]
    }
  },
  onLoad(options){
    this.changeId=options.id;

  },
  onShow(){
    wx.setNavigationBarTitle({
      title: "搜索"
    })
   this.getList=wx.getStorageSync('searchList')&&JSON.parse(wx.getStorageSync('searchList'))
    console.log(this.getList)
  },
  methods: {
    clearFun(){
      wx.removeStorageSync('searchList')
      this.getList=[]
    },
    getProduct(name){
      wx.setStorageSync('searchName',name.name)
      wx.navigateBack({
        id:this.changeId,
      })
    },
    getValue(val){
      let that=this;
      wx.setStorageSync('searchName',that.searchName)
      if(that.searchName){
        let obj={};
        obj.name=that.searchName
        this.list.push(obj);
        wx.setStorageSync('searchList',JSON.stringify(this.list))
      }

      wx.navigateBack({
        id:that.changeId,
      })

    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.history{
  padding: 0.8em;
  font-size: 0.8em;
}
.history .clear img{
  width: 1.2em;
}
.history .history_list{
  padding-top: 0.3em;
}
.history .history_item{
  color: #999;
  font-size: 0.9em;
}
</style>
